package com.ruoyi.system.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.system.domain.TMarkdownType;
import com.ruoyi.system.service.ITMarkdownTypeService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * markdown类型Controller
 * 
 * @author ruoyi
 * @date 2022-01-18
 */
@RestController
@RequestMapping("/system/markdownType")
public class TMarkdownTypeController extends BaseController
{
    @Autowired
    private ITMarkdownTypeService tMarkdownTypeService;

    /**
     * 查询markdown类型列表
     */
    @PreAuthorize("@ss.hasPermi('system:markdownType:list')")
    @GetMapping("/list")
    public TableDataInfo list(TMarkdownType tMarkdownType)
    {
        startPage();
        List<TMarkdownType> list = tMarkdownTypeService.selectTMarkdownTypeList(tMarkdownType);
        return getDataTable(list);
    }

    /**
     * 导出markdown类型列表
     */
    @PreAuthorize("@ss.hasPermi('system:markdownType:export')")
    @Log(title = "markdown类型", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, TMarkdownType tMarkdownType)
    {
        List<TMarkdownType> list = tMarkdownTypeService.selectTMarkdownTypeList(tMarkdownType);
        ExcelUtil<TMarkdownType> util = new ExcelUtil<TMarkdownType>(TMarkdownType.class);
        util.exportExcel(response, list, "markdown类型数据");
    }

    /**
     * 获取markdown类型详细信息
     */
    @PreAuthorize("@ss.hasPermi('system:markdownType:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return AjaxResult.success(tMarkdownTypeService.selectTMarkdownTypeById(id));
    }

    /**
     * 新增markdown类型
     */
    @PreAuthorize("@ss.hasPermi('system:markdownType:add')")
    @Log(title = "markdown类型", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody TMarkdownType tMarkdownType)
    {
        return toAjax(tMarkdownTypeService.insertTMarkdownType(tMarkdownType));
    }

    /**
     * 修改markdown类型
     */
    @PreAuthorize("@ss.hasPermi('system:markdownType:edit')")
    @Log(title = "markdown类型", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody TMarkdownType tMarkdownType)
    {
        return toAjax(tMarkdownTypeService.updateTMarkdownType(tMarkdownType));
    }

    /**
     * 删除markdown类型
     */
    @PreAuthorize("@ss.hasPermi('system:markdownType:remove')")
    @Log(title = "markdown类型", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(tMarkdownTypeService.deleteTMarkdownTypeByIds(ids));
    }
}
